<script setup lang="ts">
import { useRouter } from 'vue-router';
import {inject} from "vue";
import { post } from "@/axios"
import { useTokenStore } from "@/store";
import  {ElMessage} from "element-plus"


const router = useRouter();
const socket:any = inject("wsPlugin")

socket.onopen(()=>{
  console.log(socket)

  const data = {
    username: "username",
    password: "password"
  }

  socket.send(data)
})


setInterval(()=>{
  socket.send("ping")
  socket.onMessage()
},30000)

const token = useTokenStore();
if(inject("login") !== true){
  post("/User/VerifyToken",{token:token.token}).then((res:any)=>{
    if(res.status === 200){
      router.replace("/main")
    }else{
      router.push("/login")
    }
  })
}


</script>

<template>
<RouterView />
</template>

<style scoped>

</style>